﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_TypeCh : System.Web.UI.Page
{
    MyDataDataContext db = new MyDataDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack & Request.QueryString["typeId"] != null)//页面首次打开
        {
            GoodsType ChangeObj = (from r in db.GoodsType
                                   where r.GoodsTypeID == Request.QueryString["typeId"]
                                   select r).FirstOrDefault();
            typeId.Text = ChangeObj.GoodsTypeID;
            typeName.Text = ChangeObj.GoodsTypeName;
        }
    }
    protected void Change(object sender, EventArgs e)
    {
        //控件全部通过验证
        if (Page.IsValid)
        {
            GoodsType ChangeObj = (from r in db.GoodsType
                                   where r.GoodsTypeID == Request.QueryString["typeId"]
                                   select r).FirstOrDefault();
            ChangeObj.GoodsTypeID = typeId.Text;
            ChangeObj.GoodsTypeName = typeName.Text;
            //提交
            db.SubmitChanges();

            string message = "修改成功，请点击确定查看";
            string js = @"<Script language='JavaScript'>alert('" + message + "');window.close();</Script>";
            Response.Write(js);
            Page_Load(sender, e);

        }                    
    }
    protected void Backing(object sender, EventArgs e)
    {        
        Response.Redirect("Typemng.aspx");
    }

    protected void Del(object sender, EventArgs e)
    {
        GoodsType DeleteObj = (from r in db.GoodsType
                          where r.GoodsTypeID == Request.QueryString["typeId"]
                          select r).FirstOrDefault();
        //删除
        db.GoodsType.DeleteOnSubmit(DeleteObj);
        db.SubmitChanges();
        string message = "删除成功，请点击确定查看";
        string js = @"<Script language='JavaScript'>alert('" + message + "');window.close();</Script>";
        Response.Write(js);
        Page_Load(sender, e);
    }

}